package com.ym.controller.soso;

import com.github.pagehelper.PageInfo;
import com.ym.base.enums.FlagEnum;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.soso.domain.entity.SveNurseComeEntity;
import com.ym.soso.domain.param.PublishParam;
import com.ym.soso.domain.param.SveNurseComeQueryParam;
import com.ym.soso.domain.param.SveNurseComeUpdateParam;
import com.ym.soso.domain.vo.SveNurseComeListPcVO;
import com.ym.soso.service.ISveNurseComeSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 护士上门Controller
 *
 * @author ym
 * @date 2020-03-06
 */
@Api(tags = "pc-护士上门")
@RestController
@Validated
@RequestMapping("/pc/come")
public class SveNurseComeController extends BaseController {

	@Autowired
	private ISveNurseComeSV sveNurseComeSV;

	@ApiOperation("查询护士上门列表")
	@Log(dataBase = false, printBody = false, printQuery = true)
	@GetMapping("/list")
	public APIResponse<PageInfo<SveNurseComeListPcVO>> list(@Valid SveNurseComeQueryParam queryParam) {
		PageDomain.startPage();
		queryParam.setDeleted(FlagEnum.NO.getKey());
		List<SveNurseComeListPcVO> list = sveNurseComeSV.selectListPC(queryParam);
		return successPage(list);
	}

	@ApiOperation("获取护士上门详细信息")
	@Log(dataBase = false, printBody = false, printQuery = true)
	@GetMapping(value = "/info")
	public APIResponse<SveNurseComeEntity> info(@RequestParam Long id) {
		SveNurseComeEntity data = sveNurseComeSV.selectById(id);
		return successData(data);
	}

	@ApiOperation("新增/修改护士上门")
	@Log(dataBase = true, printBody = true, printQuery = false)
	@PostMapping("/update")
	public APIResponse edit(@RequestBody @Valid SveNurseComeUpdateParam updateParam) {
		if (updateParam.getId() != null && updateParam.getId() > 0) {
			sveNurseComeSV.insertPC(updateParam);
		}else{
			sveNurseComeSV.updateByIdPC(updateParam);
		}
		return success();
	}

	@ApiOperation("删除护士上门")
	@Log(dataBase = true, printBody = true, printQuery = false)
	@PostMapping("/delete")
	public APIResponse remove(@RequestBody @Valid @NotNull Long[] ids) {
		sveNurseComeSV.deleteByIds(ids);
		return success();
	}

	@Log(dataBase = true)
	@ApiOperation("发布")
	@PostMapping("/release")
	public APIResponse publish(
			@RequestBody @Valid PublishParam params
	) {
		sveNurseComeSV.publish(params);
		return success();
	}
}
